package com.haiya.command.mixcomposite;

import java.util.ArrayList;
import java.util.List;

public class Invoker implements AbstractCommand {
    private String name;

    public Invoker(String name) {
        this.name = name;
    }

    private List<AbstractCommand> children = new ArrayList<>();

    public void add(AbstractCommand command) {
        children.add(command);
    }

    public void remove(AbstractCommand command) {
        children.remove(command);
    }

    @Override
    public void execute() {
        System.out.println("Invoker " + name + " execute: ~~~~~~~~~~~~~~~~~~~~");
        for (AbstractCommand child : children) {
            child.execute();
        }
    }
}
